public class Solution997 {
    public int findJudge(int n, int[][] trust) {
        int[] in=new int[n+1];
        int[] out=new int[n+1];
        for (int[] ints : trust) {
            in[ints[1]]++;
            out[ints[0]]++;
        }
        int ans=-1;
        int count=0;
        for (int i=1;i<=n;i++){
            if (in[i]==n-1 && out[i]==0){
                count++;
                ans=i;
            }
        }
        return count>1?-1:ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution997().findJudge(3,new int[][]{{1,3},{2,3}}));
    }
}
